import React from 'react';
import {WeaErrorPage, WeaTools, WeaEchart, WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
//图表元素
class EChartView extends React.Component {
	componentDidUpdate(){
        this.refs.chart && this.refs.chart.resize()
	}

	render() {
		const { eid, width, height, option, charttype, key } = this.props;
		return (<div style={{width,height,margin:'0 auto'}} id={`reportformchart_${eid}`}>
                  {option && <WeaEchart ecId={`${this && this.props && this.props.ecId || ''}_WeaEchart@vh47e1`} chartName={''} ref={'chart'} key={key} useDefault={true} key={charttype} style={{width:width,height:height}} option={option} series={option.series}/>}
           </div>);
	}
}


class MyErrorHandler extends React.Component {
	render() {
		const hasErrorMsg = this.props.error && this.props.error !== "";
		return (
			<WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@wnd9y3`} msg={hasErrorMsg?this.props.error:getLabel(385218,"对不起，该页面异常，请联系管理员！")} />
		);
	}
}
EChartView = WeaTools.tryCatch(React, MyErrorHandler, {
	error: ""
})(EChartView);

export default EChartView;